<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>zapmenot.material &mdash; Zapmenot 0.1 documentation</title>
      <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    <script src="../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
            <a href="../../index.html" class="icon icon-home"> Zapmenot
          </a>
              <div class="version">
                0.1
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../license.html">Licence &amp; Disclaimer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../materials.html">Material Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../isotopes.html">Isotope Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modeling.html">Modeling in ZapMeNot</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../results.html">Generating Results</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../graphics.html">We Want Pictures!</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../theory-and-methods.html">Theory and Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../benchmarks.html">Benchmarking</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../module-docs.html">Module Contents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../developer.html">Developer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../version-history.html">Version History</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">Zapmenot</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home"></a></li>
          <li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
      <li class="breadcrumb-item active">zapmenot.material</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for zapmenot.material</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="kn">import</span> <span class="n">Akima1DInterpolator</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">numbers</span>
<span class="c1"># from collections.abc import Iterable</span>
<span class="kn">import</span> <span class="nn">yaml</span>
<span class="kn">import</span> <span class="nn">pkg_resources</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">yaml</span> <span class="kn">import</span> <span class="n">CLoader</span> <span class="k">as</span> <span class="n">MyLoader</span><span class="p">,</span> <span class="n">CDumper</span> <span class="k">as</span> <span class="n">MyDumper</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">yaml</span> <span class="kn">import</span> <span class="n">FullLoader</span> <span class="k">as</span> <span class="n">MyLoader</span><span class="p">,</span> <span class="n">SafeDumper</span> <span class="k">as</span> <span class="n">MyDumper</span>


<div class="viewcode-block" id="Material"><a class="viewcode-back" href="../../module-docs.html#zapmenot.material.Material">[docs]</a><span class="k">class</span> <span class="nc">Material</span><span class="p">:</span>
<span class="w">    </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Encapsulates the data in the MaterialLibrary.yml file.</span>

<span class="sd">    Makes available the mean free path, mass</span>
<span class="sd">    energy absorption coefficient, the mass attenuation coefficient,</span>
<span class="sd">    and the exposure buildup factor of the requested material.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    name : :class: `str`</span>
<span class="sd">        The material to be extracted from the material library</span>
<span class="sd">    &quot;&quot;&quot;</span>

<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    _library</span>
<span class="sd">    _name</span>
<span class="sd">    _density : float</span>
<span class="sd">        Density of the material in g/cm\ :sup:`3`</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="n">_library</span> <span class="o">=</span> <span class="kc">None</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Material name is not a string: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>

        <span class="c1"># initialize the class library if it has not already been done</span>
        <span class="k">if</span> <span class="n">Material</span><span class="o">.</span><span class="n">_library</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">path</span> <span class="o">=</span> <span class="s1">&#39;materialLibrary.yml&#39;</span>
            <span class="n">filepath</span> <span class="o">=</span> <span class="n">pkg_resources</span><span class="o">.</span><span class="n">resource_filename</span><span class="p">(</span><span class="vm">__name__</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span>
            <span class="n">stream</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">filepath</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">Material</span><span class="o">.</span><span class="n">_library</span> <span class="o">=</span> <span class="n">yaml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">stream</span><span class="p">,</span> <span class="n">Loader</span><span class="o">=</span><span class="n">MyLoader</span><span class="p">)</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="c1"># check to see if the name is in the library</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">Material</span><span class="o">.</span><span class="n">_library</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Material not found in the Material Library&quot;</span><span class="p">)</span>

        <span class="c1"># initialize the object</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_name</span> <span class="o">=</span> <span class="n">name</span>
        <span class="n">properties</span> <span class="o">=</span> <span class="n">Material</span><span class="o">.</span><span class="n">_library</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_name</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_density</span> <span class="o">=</span> <span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;density&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_atten_energy_bins</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
            <span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;mass-atten-coff-energy&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_mass_atten_coff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;mass-atten-coff&quot;</span><span class="p">))</span>
        <span class="c1"># the mass energy absorption coefficient is optional for a material</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_en_abs_energy_bins</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
            <span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;mass-en-abs-coff-energy&quot;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_mass_en_abs_coff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;mass-en-abs-coff&quot;</span><span class="p">))</span>
        <span class="c1"># the buildup factor data is optional for a material</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_gp_energy_bins</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;gp-coff-energy&quot;</span><span class="p">))</span>
        <span class="n">gp_data</span> <span class="o">=</span> <span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;gp-coeff&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">gp_data</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_b</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_c</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_a</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_X</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_d</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">gp_array</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">gp_data</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_b</span> <span class="o">=</span> <span class="n">gp_array</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_c</span> <span class="o">=</span> <span class="n">gp_array</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_a</span> <span class="o">=</span> <span class="n">gp_array</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_X</span> <span class="o">=</span> <span class="n">gp_array</span><span class="p">[:,</span> <span class="mi">3</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_gp_d</span> <span class="o">=</span> <span class="n">gp_array</span><span class="p">[:,</span> <span class="mi">4</span><span class="p">]</span>
            <span class="c1"># here we are building interpolators based on the Akima method.</span>
            <span class="c1"># For more information on the use of Akima method on G-P coefficients,</span>
            <span class="c1"># see https://www.nrc.gov/docs/ML1905/ML19059A414.pdf</span>
            <span class="c1"># &quot;QAD-CGGP2 and G33-GP2: Revised Version of QAD-CGGP and G33-GP&quot;</span>
            <span class="n">logE</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_gp_energy_bins</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_bi</span> <span class="o">=</span> <span class="n">Akima1DInterpolator</span><span class="p">(</span><span class="n">logE</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_b</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ci</span> <span class="o">=</span> <span class="n">Akima1DInterpolator</span><span class="p">(</span><span class="n">logE</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_c</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ai</span> <span class="o">=</span> <span class="n">Akima1DInterpolator</span><span class="p">(</span><span class="n">logE</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_a</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_Xi</span> <span class="o">=</span> <span class="n">Akima1DInterpolator</span><span class="p">(</span><span class="n">logE</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_X</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_di</span> <span class="o">=</span> <span class="n">Akima1DInterpolator</span><span class="p">(</span><span class="n">logE</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_d</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;:class:`str` : The name of the material&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">density</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;:class:`float` : The density of the material in g/cm\ :sup:`3` &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_density</span>

    <span class="nd">@density</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">density</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid density&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">value</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid density&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_density</span> <span class="o">=</span> <span class="n">value</span>

<div class="viewcode-block" id="Material.get_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.material.Material.get_mfp">[docs]</a>    <span class="k">def</span> <span class="nf">get_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energy</span><span class="p">,</span> <span class="n">distance</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mean free path for a given distance and photon energy</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        energy : :class:`float`</span>
<span class="sd">            The photon energy in MeV</span>
<span class="sd">        distance : :class:`float`</span>
<span class="sd">            The distance through the material in cm</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`float`</span>
<span class="sd">            The mean free path in the material</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid energy: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">energy</span><span class="p">))</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">distance</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">)</span> <span class="ow">or</span> \
           <span class="n">distance</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid distance: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">distance</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">distance</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_density</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_mass_atten_coeff</span><span class="p">(</span><span class="n">energy</span><span class="p">)</span></div>

<div class="viewcode-block" id="Material.get_mass_atten_coeff"><a class="viewcode-back" href="../../module-docs.html#zapmenot.material.Material.get_mass_atten_coeff">[docs]</a>    <span class="k">def</span> <span class="nf">get_mass_atten_coeff</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energy</span><span class="p">):</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Calculates the mass attenuation coefficient at the given energy</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        energy : :class:`float`</span>
<span class="sd">            The photon energy in MeV</span>

<span class="sd">        Raises</span>
<span class="sd">        ------</span>
<span class="sd">        ValueError</span>
<span class="sd">            Photon energy is out of range</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`float`</span>
<span class="sd">            The mass attenuation coefficient in cm\ :sup:`2`/g</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid energy: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">energy</span><span class="p">))</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">energy</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_atten_energy_bins</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">or</span> \
                <span class="p">(</span><span class="n">energy</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_atten_energy_bins</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Photon energy is out of range&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">power</span><span class="p">(</span><span class="mf">10.0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">interp</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">energy</span><span class="p">),</span>
                                        <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_atten_energy_bins</span><span class="p">),</span>
                                        <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_mass_atten_coff</span><span class="p">)))</span></div>

<div class="viewcode-block" id="Material.get_mass_energy_abs_coeff"><a class="viewcode-back" href="../../module-docs.html#zapmenot.material.Material.get_mass_energy_abs_coeff">[docs]</a>    <span class="k">def</span> <span class="nf">get_mass_energy_abs_coeff</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energy</span><span class="p">):</span>
<span class="w">        </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;Calculates the mass energy absorption coefficient at the given energy</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        energy : :class:`float`</span>
<span class="sd">            The photon energy in MeV</span>

<span class="sd">        Raises</span>
<span class="sd">        ------</span>
<span class="sd">        ValueError</span>
<span class="sd">            Photon energy is out of range</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`float`</span>
<span class="sd">            The mass energy absorption coefficient in cm\ :sup:`2`/g</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid energy: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">energy</span><span class="p">))</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">energy</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_en_abs_energy_bins</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">or</span> \
                <span class="p">(</span><span class="n">energy</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_en_abs_energy_bins</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Photon energy is out of range&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">power</span><span class="p">(</span><span class="mf">10.0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">interp</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">energy</span><span class="p">),</span>
                                        <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_en_abs_energy_bins</span><span class="p">),</span>
                                        <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_mass_en_abs_coff</span><span class="p">)))</span></div>

<div class="viewcode-block" id="Material.get_buildup_factor"><a class="viewcode-back" href="../../module-docs.html#zapmenot.material.Material.get_buildup_factor">[docs]</a>    <span class="k">def</span> <span class="nf">get_buildup_factor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energy</span><span class="p">,</span> <span class="n">mfps</span><span class="p">,</span> <span class="n">formula</span><span class="o">=</span><span class="s2">&quot;GP&quot;</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the photon buildup factor at the given energy and mfp</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        energy : :class:`float`</span>
<span class="sd">            The photon energy in MeV</span>
<span class="sd">        mfps : :class:`float`, :class:`list`, or :class:`numpy.ndarray`</span>
<span class="sd">            One or more mean free path values through the material</span>
<span class="sd">        formula : :class:`str`</span>
<span class="sd">            The format of the buildup factor (only &#39;GP&#39; is currently supported)</span>

<span class="sd">        Raises</span>
<span class="sd">        ------</span>
<span class="sd">        ValueError</span>
<span class="sd">            Photon energy is out of range</span>
<span class="sd">        ValueError</span>
<span class="sd">            Only GP buildup factors are currently supported</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`float` or :class:`numpy.ndarray`</span>
<span class="sd">            A vector of photon exposure buildup factors in air, one for</span>
<span class="sd">            each specified mfp</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_b</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Material has no buildup factor data available&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">formula</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Buildup factor type is not a string: &quot;</span> <span class="o">+</span>
                             <span class="nb">str</span><span class="p">(</span><span class="n">formula</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">formula</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s2">&quot;GP&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Only GP Buildup Factors are currently supported&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid energy: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">energy</span><span class="p">))</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">mfp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">mfps</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;mfps have invalid array structure&quot;</span><span class="p">)</span>
        <span class="c1"># mfps must be non-negative</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">amin</span><span class="p">(</span><span class="n">mfp</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;negative mfp&quot;</span><span class="p">)</span>

        <span class="c1"># find the bounding array indices</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">energy</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_energy_bins</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">or</span> \
                <span class="p">(</span><span class="n">energy</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gp_energy_bins</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Photon energy is out of range&quot;</span><span class="p">)</span>
        <span class="n">logE</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">energy</span><span class="p">)</span>
        <span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bi</span><span class="p">(</span><span class="n">logE</span><span class="p">)</span>
        <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ci</span><span class="p">(</span><span class="n">logE</span><span class="p">)</span>
        <span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ai</span><span class="p">(</span><span class="n">logE</span><span class="p">)</span>
        <span class="n">X</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_Xi</span><span class="p">(</span><span class="n">logE</span><span class="p">)</span>
        <span class="n">d</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_di</span><span class="p">(</span><span class="n">logE</span><span class="p">)</span>

        <span class="n">bf</span> <span class="o">=</span> <span class="n">Material</span><span class="o">.</span><span class="n">_GP</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">X</span><span class="p">,</span> <span class="n">mfp</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">bf</span></div>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_GP</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">X</span><span class="p">,</span> <span class="n">mfp</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the photon buildup factor using Geometric Progression</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        a : float</span>
<span class="sd">            A GP fitting coefficient</span>
<span class="sd">        b : float</span>
<span class="sd">            A GP fitting coefficient</span>
<span class="sd">        c : float</span>
<span class="sd">            A GP fitting coefficient</span>
<span class="sd">        d : float</span>
<span class="sd">            A GP fitting coefficient</span>
<span class="sd">        X : float</span>
<span class="sd">            A GP fitting coefficient</span>
<span class="sd">        mfp : float (for a single mfp) or a numpy array (for several mfp&#39;s)</span>
<span class="sd">            The mean free path through the material in cm</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        float or :class:`numpy.ndarray`</span>
<span class="sd">            Vector of photon exposure buildup factors in air</span>

<span class="sd">        Important Details</span>
<span class="sd">        -----------------</span>
<span class="sd">        The number of mean free paths (mfp) used to calculate the buildup</span>
<span class="sd">        factor is limited to a value of 40 or less.  This is an inherent</span>
<span class="sd">        limitation of the source document, ANS-6.4.3-1991.  In normal use this</span>
<span class="sd">        limitation is only expected to be encountered in cases involving low</span>
<span class="sd">        energy photons (with a relatively small mean free path) and</span>
<span class="sd">        thick shields.  In those instances the uncolided flux should be very</span>
<span class="sd">        small.  Even with a larger buildup factor the contribution of these</span>
<span class="sd">        photons to exposure should be minimal and other higher energy photons</span>
<span class="sd">        should dominate.  The exception would be xrays combined with very thick</span>
<span class="sd">        shiekding.  In those cases a higher-order shielding code</span>
<span class="sd">        should be used.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">mfp</span><span class="p">)</span> <span class="o">==</span> <span class="p">():</span>
            <span class="k">if</span> <span class="n">mfp</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>  <span class="c1"># this accomodates a little rounding error</span>
                <span class="k">return</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">60</span><span class="p">:</span>
                <span class="n">mfp</span> <span class="o">=</span> <span class="mi">60</span>  <span class="c1"># limit results to mfp &lt;= 60</span>
            <span class="k">if</span> <span class="n">mfp</span> <span class="o">&lt;=</span> <span class="mi">40</span><span class="p">:</span>
                <span class="n">K</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="p">(</span><span class="n">mfp</span><span class="o">**</span><span class="n">a</span><span class="p">))</span> <span class="o">+</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="n">mfp</span><span class="o">/</span><span class="n">X</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)))</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">K35</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="p">(</span><span class="mi">35</span><span class="o">**</span><span class="n">a</span><span class="p">))</span> <span class="o">+</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="mi">35</span><span class="o">/</span><span class="n">X</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)))</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span>
                <span class="n">K40</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="p">(</span><span class="mi">40</span><span class="o">**</span><span class="n">a</span><span class="p">))</span> <span class="o">+</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="mi">40</span><span class="o">/</span><span class="n">X</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)))</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span>
                <span class="n">part1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">((</span><span class="n">K40</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">K35</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span>
                <span class="n">part2</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="p">(</span><span class="n">mfp</span><span class="o">/</span><span class="mi">35</span><span class="p">)</span><span class="o">**</span><span class="mf">0.1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="p">(</span><span class="mi">40</span><span class="o">/</span><span class="mi">35</span><span class="p">)</span><span class="o">**</span><span class="mf">0.1</span><span class="p">)</span>
                <span class="n">K</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">K35</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">part1</span><span class="o">*</span><span class="n">part2</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">K</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">answer</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">b</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">mfp</span>
            <span class="k">elif</span> <span class="n">K</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">answer</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">b</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">((</span><span class="n">K</span><span class="o">**</span><span class="n">mfp</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">K</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">answer</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">mfp</span><span class="p">[</span><span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">60</span><span class="p">]</span> <span class="o">=</span> <span class="mi">60</span>
            <span class="n">mfp</span><span class="p">[</span><span class="n">mfp</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">K</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">mfp</span><span class="o">.</span><span class="n">size</span><span class="p">)</span>  <span class="c1"># default values for mfp = 0 -&gt; buildup factor = 1</span>
            <span class="c1"># cases that do not need extrapolation</span>
            <span class="n">K</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="n">mfp</span> <span class="o">&lt;=</span> <span class="mi">40</span><span class="p">)]</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="p">(</span><span class="n">mfp</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="n">mfp</span> <span class="o">&lt;=</span> <span class="mi">40</span><span class="p">)]</span><span class="o">**</span><span class="n">a</span><span class="p">))</span> <span class="o">+</span> \
                <span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="n">mfp</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="n">mfp</span> <span class="o">&lt;=</span> <span class="mi">40</span><span class="p">)]</span><span class="o">/</span><span class="n">X</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)))</span> <span class="o">/</span> \
                <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span>
            <span class="c1"># cases that do need extrapolation</span>
            <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">40</span><span class="p">):</span>  <span class="c1"># skip this step if no extrapolations needed</span>
                <span class="n">K35</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="p">(</span><span class="mi">35</span><span class="o">**</span><span class="n">a</span><span class="p">))</span> <span class="o">+</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="mi">35</span><span class="o">/</span><span class="n">X</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)))</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span>
                <span class="n">K40</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span> <span class="o">*</span> <span class="p">(</span><span class="mi">40</span><span class="o">**</span><span class="n">a</span><span class="p">))</span> <span class="o">+</span> <span class="p">(</span><span class="n">d</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="mi">40</span><span class="o">/</span><span class="n">X</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)))</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">tanh</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">))</span>
                <span class="n">K</span><span class="p">[</span><span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">40</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">K35</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">((</span><span class="n">K40</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">K35</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span> <span class="o">*</span>
                           <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="p">(</span><span class="n">mfp</span><span class="p">[</span><span class="n">mfp</span> <span class="o">&gt;</span> <span class="mi">40</span><span class="p">]</span><span class="o">/</span><span class="mi">35</span><span class="p">)</span><span class="o">**</span><span class="mf">0.1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="p">(</span><span class="mi">40</span><span class="o">/</span><span class="mi">35</span><span class="p">)</span><span class="o">**</span><span class="mf">0.1</span><span class="p">))</span>

            <span class="n">answers</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">mfp</span><span class="o">.</span><span class="n">size</span><span class="p">)</span>  <span class="c1"># set default values to 1</span>
            <span class="n">answers</span><span class="p">[</span><span class="n">K</span> <span class="o">==</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">b</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">mfp</span><span class="p">[</span><span class="n">K</span> <span class="o">==</span> <span class="mi">1</span><span class="p">]</span>
            <span class="n">answers</span><span class="p">[</span><span class="n">K</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> \
                <span class="p">(</span><span class="n">b</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">power</span><span class="p">(</span><span class="n">K</span><span class="p">[</span><span class="n">K</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">],</span> <span class="n">mfp</span><span class="p">[</span><span class="n">K</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">]))</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">K</span><span class="p">[</span><span class="n">K</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">answers</span></div>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2019 - 2023, Alan Ford..
      <span class="lastupdated">Last updated on Feb 12, 2023.
      </span></p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>